﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irony.Parsing;

namespace ConciseMarkupLanguage.Terminals
{
    class VariableTerminal : Terminal
    {
        public VariableTerminal(string name) : base(name)
        {
        }

        public override IList<string> GetFirsts()
        {
            return new[] { "$" };
        }

        public override Token TryMatch(ParsingContext context, ISourceStream source)
        {
            if (source.PreviewChar != '$') return null;
            do
            {
                source.PreviewPosition++;
            } while (!source.EOF() && char.IsLetter(source.PreviewChar));
            
            var token = source.CreateToken(OutputTerminal);
            return token;
        }
    }
}
